-
Notifications
You must be signed in to change notification settings - Fork 13.3k
StableMIR: Implement CompilerInterface
#139852
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
r? @celinval btw should we create a tracking issue for this? |
@@ -233,7 +234,12 @@ where | |||
mir_consts: IndexMap::default(), | |||
layouts: IndexMap::default(), | |||
})); | |||
stable_mir::compiler_interface::run(&tables, || init(&tables, f)) | |||
|
|||
let interface = CompilerInterface { cx: tables }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put the interface here since I'd prefer not to refactor the launch process now. It would be more appropriate to do this at the end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
/// Stable-MIR’s interface to compiler internals. | ||
/// All internal queries must go through [`Context`]. | ||
/// | ||
/// Do not use this directly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please document that this is currently used in the macro expansion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm tbh it is not. We directly create a CompilerInterface
in the rustc_internal::run()
function for now, which is also called by pretty::write_smir_pretty()
, not only the run_driver!
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but yeah, maybe we can make it into a macro
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh my bad! I got it wrong...
// A thread local variable that stores a pointer to the tables mapping between TyCtxt | ||
// datastructures and stable MIR datastructures | ||
/// Stable-MIR’s interface to compiler internals. | ||
/// All internal queries must go through [`Context`]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove Context
in this PR?
Also, I think it may be worth documenting this a bit better, so people know why this is here. Something on the lines that this structure will serve as a bridge between StableMIR and the rustc_smir which will provide similar APIs but based on internal rustc constructs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove
Context
in this PR?
Sorry that i didn't get it. You mean we directly write something like impl<'tcx> TablesWrapper<'tcx>, then move everything that used to be in Context to there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh and then we create a brand-new Context
in rustc_smir
, and gradually move methods from TablesWrapper
to it until TablesWrapper
is completely hollowed out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you don't need the trait anymore. Next step I believe would be to move the stable / internal calls out of the TablesWrapper.
Btw, you could rename TablesWrapper to Context too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, feel free to improve the name scheme, it's not my strongest skill. LoL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm what if we change CompilerInterface
to SmirInterface
?🤔
scoped_tls::scoped_thread_local!(static TLV: Cell<*const ()>); | ||
|
||
pub fn run<F, T>(context: &dyn Context, f: F) -> Result<T, Error> | ||
pub fn run<'tcx, T, F>(interface: &CompilerInterface<'tcx>, f: F) -> Result<T, Error> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@oli-obk Any chance you can take a look at this TLV magic? I could use a second pair of eyes here. Thanks!
pub(crate) struct Context<'tcx>(pub RefCell<Tables<'tcx>>); | ||
|
||
impl<'tcx> Context<'tcx> { | ||
pub(crate) fn target_info(&self) -> MachineInfo { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might as well make these public so we don't have to update the visibility when we pull the StableMir stuff back to its crate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
- With `Context` wrapped by `SmirInterface`, the stable-mir's TLV stores a pointer to `SmirInterface`, while the rustc-specific TLV stores a pointer to tables. - This PR make the `rustc_smir` mod public.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Thanks.
Co-authored-by: Celina G. Val <[email protected]>
@bors r+ rollup |
StableMIR: Implement `CompilerInterface` This PR implements part of [the document](https://hackmd.io/`@celinaval/H1lJBGse0).` With `TablesWrapper` wrapped by `CompilerInterface`, the stable-mir's TLV stores a pointer to `CompilerInterface`, while the rustc-specific TLV stores a pointer to tables.
Rollup of 23 pull requests Successful merges: - rust-lang#139261 (mitigate MSVC alignment issue on x86-32) - rust-lang#139307 (std: Add performance warnings to HashMap::get_disjoint_mut) - rust-lang#139700 (Autodiff flags) - rust-lang#139752 (set subsections_via_symbols for ld64 helper sections) - rust-lang#139809 (Don't warn about `v128` in wasm ABI transition) - rust-lang#139852 (StableMIR: Implement `CompilerInterface`) - rust-lang#139945 (Extend HIR to track the source and syntax of a lifetime) - rust-lang#140028 (`deref_patterns`: support string and byte string literals in explicit `deref!("...")` patterns) - rust-lang#140139 (rustc_target: Adjust RISC-V feature implication) - rust-lang#140143 (Move `sys::pal::os::Env` into `sys::env`) - rust-lang#140148 (CI: use aws codebuild for job dist-arm-linux) - rust-lang#140150 (fix MAX_EXP and MIN_EXP docs) - rust-lang#140172 (Make algebraic functions into `const fn` items.) - rust-lang#140177 ([compiletest] Parallelize test discovery) - rust-lang#140181 (Remove `synstructure::Structure::underscore_const` calls.) - rust-lang#140184 (Update doc of cygwin target) - rust-lang#140186 (Rename `compute_x` methods) - rust-lang#140187 ([AIX] Handle AIX dynamic library extensions within c-link-to-rust-dylib run-make test) - rust-lang#140191 (Remove git repository from git config) - rust-lang#140194 (minicore: Have `//@ add-core-stubs` also imply `-Cforce-unwind-tables=yes`) - rust-lang#140195 (triagebot: label minicore changes w/ `A-test-infra-minicore` and ping jieyouxu on changes) - rust-lang#140202 (Make #![feature(let_chains)] bootstrap conditional in compiler/) - rust-lang#140214 (Remove comment about handling non-global where bounds with corresponding projection) r? `@ghost` `@rustbot` modify labels: rollup
StableMIR: Implement `CompilerInterface` This PR implements part of [the document](https://hackmd.io/``@celinaval/H1lJBGse0).`` With `TablesWrapper` wrapped by `CompilerInterface`, the stable-mir's TLV stores a pointer to `CompilerInterface`, while the rustc-specific TLV stores a pointer to tables.
This PR implements part of the document.
With
TablesWrapper
wrapped byCompilerInterface
, the stable-mir's TLV stores a pointer toCompilerInterface
, while the rustc-specific TLV stores a pointer to tables.